
import { fetchItems } from '@a'


export default {
  // 命名空间
  namespace: 'count',
  state: {
    num: 0,
    items: []
  },
  reducers: {
    add(state: any, action: any) {
      console.log(action);
      state.num += action.num
      return {
        ...state
      }
    },
    // 接受异步接口返回数据 赋值给items
    initItems (state: any, action: any) {
      state.items = action.data
      return {
        ...state
      }
    }
  },
  // 处理异步
  effects: {
    *getItems(action: any, { put, call }: any) {
      console.log(action,111);
      
      const res = yield call(fetchItems, action.params);
      if (res.data.code === 0) {
        yield put({ type: 'initItems', data: res.data.data.result });
      }
      
      // put相当于dispatch
      // 
    },
  },
};
        